package enumdemo;

/**
 * @Author 12629
 * @Description：
 */
public enum TestEnum {

    RED(1,"红色"),
    BLACK(3,"黑色"),
    GREEN(4,"绿色");

    private int ordinal;
    private String color;

    TestEnum(int ordinal, String color) {
        this.ordinal = ordinal;
        this.color = color;
    }

    public static void main(String[] args) {
        //为什么不在 Enum这个类中有？
        TestEnum[] testEnums = TestEnum.values();
        for (int i = 0; i < testEnums.length; i++) {
            System.out.println(testEnums[i]+" " + testEnums[i].ordinal());
        }
        System.out.println("=====");
        try {
            TestEnum testEnum = TestEnum.valueOf("RED");
            System.out.println(testEnum);
        }catch (IllegalArgumentException e) {

        }

        int to = RED.compareTo(BLACK);
        System.out.println(to);

    }

    public static void main1(String[] args) {
        TestEnum testEnum = TestEnum.BLACK;
        switch (testEnum) {
            case BLACK:
                System.out.println("black");
                break;
            case RED:
                System.out.println("RED");
                break;
            case GREEN:
                System.out.println("GREEN");
                break;
            default:
                System.out.println("default");
                break;
        }
    }
}


